using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Resources;
using System.Data;
using HSHLogicLayer;

namespace TaskVision
{
	public partial class AddKenForm : System.Windows.Forms.Form
	{
		private ResourceManager m_ResourceManager = new ResourceManager("TaskVision.Localize", System.Reflection.Assembly.GetExecutingAssembly());
		
		public AddKenForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

		}
		
		private void btnOk_Click(object sender, System.EventArgs e)
		{
			if (txtKenName.Text.Trim() != String.Empty)
			{
				int KenID = -1;
                DataLayerResult dlResult = DataLayerSingleton.Instance().InsertKen(ref KenID, txtKenName.Text.Trim(),cmbRegionName.SelectedIndex + 1);

				// if database update was successful add the Ken to our local data
				if (dlResult.ResultType == DataLayerResultType.Success)
				{
                    DataRow dr = DataLayerSingleton.Instance().DsKens.Kens.NewRow();
					dr["KenID"] = KenID;
					dr["KenName"] = txtKenName.Text.Trim();
                    dr["RegionName"] = cmbRegionName.SelectedItem.ToString();
                    dr["RegionID"] = cmbRegionName.SelectedIndex + 1;
                    DataLayerSingleton.Instance().DsKens.Kens.Rows.Add(dr);

                    HebMessageBox.Show(m_ResourceManager.GetString("Remember_To_Add_Authorization"));
				}
				else
				{
					HebMessageBox.Show(m_ResourceManager.GetString("Unable_to_add_Ken"));
					this.DialogResult = DialogResult.None;
				}
			}
			else
			{
				this.DialogResult = DialogResult.None;
			}

			this.Close();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

        private void AddKenForm_Load(object sender, EventArgs e)
        {
            cmbRegionName.SelectedIndex = 0;
        }
	}
}
